// miniprogram/pages/checkProject/changeStatus/changeStatus.js
var app = getApp();
const host = app.globalData.host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:['方案设计阶段',
            '什么阶段',
            '测试阶段'],
    statusIndex:0,
    projectId:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var statusIndex = this.data.status.indexOf(options.projectStatus);
    this.setData({
      statusIndex: statusIndex,
      projectId: options.projectId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log("页面卸载");
    var that = this;
    wx.request({
      url: host + 'city360/updateProject',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        projectStatus: that.data.status[that.data.statusIndex],
        projectId: that.data.projectId,
      },
      complete: res => {
        console.log(res);
        if (res.statusCode.toString()[0] === '2') {
          console.log("更改成功");
        }
      }
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  bindStatusChange: function(e){
    console.log("选择改变", e);
    this.setData({
      statusIndex: e.detail.value,
    });
    var that = this;
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.data.projectInfo.projectStatus = that.data.status[that.data.statusIndex];
    prevPage.setData({
      projectInfo: prevPage.data.projectInfo
    });
  },


})